# # -*- coding: utf-8 -*-
import hashlib
#
from selenium import webdriver
from selenium.webdriver.common.by import By
import ddddocr
import os
import pymysql
# from flask import Flask, jsonify, make_response, request
# import xlwt
# from io import BytesIO
# current_path = os.path.abspath(os.path.dirname(__file__))
# parent_path = os.path.abspath(os.path.join(current_path, os.path.pardir))
# parent_path = parent_path.replace('\\','/')
# print(parent_path)
# current_dir = os.getcwd()
# print(current_dir)
# app = Flask(__name__)
# #
# # 将数据导出为 Excel 的路由
#
# result = []
#     # 创建Excel工作簿和工作表
# output = BytesIO()
# workbook = xlwt.Workbook()
# sheet = workbook.add_sheet('Users')
#
# # 将标题行写入工作表
# header_row = ['username', 'password']
# for i in range(len(header_row)):
#     sheet.write(0, i, header_row[i])
#
# # 将数据行写入工作表
# if result:
#     row = 1
#     for row_data in result:
#         for col in range(len(row_data)):
#             sheet.write(row, col, str(row_data[col]))
#         row += 1
#
# # 保存并关闭 Excel 工作簿
# workbook.save(output)
# output.seek(0)
#
# # 使用 Excel 文件附件准备响应
# response = make_response(output.getvalue())
# response.headers['Content-Disposition'] = 'attachment; filename=users.xls'
# response.headers['Content-Type'] = 'application/vnd.ms-excel'
#
# # 关闭数据库连接并返回响应
#
#
#
#
#
# import threading
# import queue
# import time
#
# def process_data(data):
#     # 在此处定义数据处理逻辑
#     return data['user_name'],data['class_name']
#
# def process_thread(data_list):
#     while True:
#         try:
#             # 从线程安全的队列中读取数据
#             data = data_list.pop(0)
#         except IndexError:  # 如果队列为空，则跳出循环
#             break
#         else:
#             # 进行数据处理
#             result_queue.put(process_data(data))
#
# data_list =[]
# # 假设有一百万条数据
# # 读取数据至data_list中
# # ...
# # 创建10个线程并将数据列表传入
# result_queue = queue.Queue()
# thread_list = []
# for i in range(5):
#   t = threading.Thread(target=process_thread, args=[data_list])
#   thread_list.append(t)
#   t.start()
# # 等待所有线程完成
# for t in thread_list:
#   t.join()
# result_list = []
# while not result_queue.empty():
#   result_list.append(result_queue.get())
# print(result_list)
# def md5_jia(a):
#   a = str(a) + 'awdadbnaiwudbaiudnhaiwudai'
#   md5_hash = hashlib.md5(a.encode('utf-8')).hexdigest()
#   return md5_hash
#
# print(md5_jia(123))
service_dir = os.getcwd().replace('\\','/').replace('views','chromedriver_win32/chromedriver.exe')
print(service_dir)
#
#
#
# import xlrd
#
# workbook = xlrd.open_workbook('C:/Users/27376/Desktop/123456.xls')
# worksheet = workbook.sheet_by_index(0)
# lis = []
# for row in range(1,worksheet.nrows):
#     row_data = []
#     for col in range(worksheet.ncols):
#         cell_value = worksheet.cell_value(row, col)
#         row_data.append(cell_value)
#     row_data[0] = str(row_data[0]).split('.')[0]
#     row_data ={
#         'username':row_data[0],
#         'password':row_data[1]
#     }
#     lis.append(row_data)
#
# print(lis)
#
# lis = [1,2,3,4,5]
# a =list()
# num = 1
# for i in range(1,len(lis)+1):
#     num *=i
# print(num)
# print(a,'\n',len(a))
#
import time
# conn = pymysql.connect(
#     host='localhost',
#     port=3306,
#     user='root',
#     password='123456',
#     db='spiders',
#     charset='utf8mb4'
# )
#
# # 获取游标
# cursor = conn.cursor()

# wd = webdriver.Chrome()

# lis = []
# wd.implicitly_wait(3)
# user_names = '2261001203096'
# passwords = 'Ouchn19930315'
# # 调用WebDriver 对象的get方法 可以让浏览器打开指定网址
# wd.get('https://iam.pt.ouchn.cn/am/UI/Login')
# # 根据id选择元素，返回的就是该元素对应的WebElement对象
# user_name = wd.find_element(By.ID, 'loginName')
# password = wd.find_element(By.ID, 'password')
# login = wd.find_element(By.ID, 'button')
# img_code = wd.find_element(By.ID, 'validateCode')
# img = wd.find_element(By.ID, 'kaptchaImage')
#
# # 获取图片验证码 图片 并给与名字 同名覆盖 不会占用太多资源
#
# current_dir = os.getcwd()
#
# img_name = str(current_dir + f"\{str(user_names)}.png")
#
# with open(img_name, 'wb') as f:
#     f.write(img.screenshot_as_png)
#
# # 图片验证实例
# ocr = ddddocr.DdddOcr()
# with open(img_name, 'rb') as f:
#     img_bytes = f.read()
# code = ocr.classification(img_bytes)
#
# user_name.send_keys(user_names)
# password.send_keys(passwords)
#
# img_code.send_keys(code)
# # 点击事件
# login.click()
# wd.get('https://menhu.pt.ouchn.cn/site/ouchnPc/index')
# time.sleep(2)
# name = ""
# try:
#     name = wd.find_element(By.CSS_SELECTOR,
#                            'body > div:nth-child(1) > div.ouchnPc_index > div.ouchnPc_index_main > div.ouchnPc_index_info.w > div.swiper-wrap > div.swiper-container.swiper-container-horizontal > div.swiper-wrapper > div.swiper-slide.ouchnPc_index_info_left_teacher.swiper-slide-active > div > div.photo_name.student_height > div > span')
#     name = name.get_attribute('innerHTML')
# except Exception as e:
#     wd.get('https://menhu.pt.ouchn.cn/site/ouchnPc/index')
#     name = wd.find_element(By.CSS_SELECTOR,
#                            'body > div:nth-child(1) > div.ouchnPc_index > div.ouchnPc_index_main > div.ouchnPc_index_info.w > div.swiper-wrap > div.swiper-container.swiper-container-horizontal > div.swiper-wrapper > div.swiper-slide.ouchnPc_index_info_left_teacher.swiper-slide-active > div > div.photo_name.student_height > div > span')
#     name = name.get_attribute('innerHTML')
#
# now_total_element = wd.find_element(By.CSS_SELECTOR,
#                                     "body > div:nth-child(1) > div.ouchnPc_index > div.ouchnPc_index_main > div.ouchnPc_index_course.w > div > span.el-pagination__total")
# now_total = now_total_element.get_attribute("innerHTML").split(" ")[1]
# if now_total != 0:
#     if int(now_total) <= 6:
#         for i in range(1, int(now_total) + 1):
#             class_name = wd.find_element(By.CSS_SELECTOR,
#                                          'body > div:nth-child(1) > div.ouchnPc_index > div.ouchnPc_index_main > div.ouchnPc_index_course.w > ul > li:nth-child(%s) > div > div > p' % (
#                                              i))
#             lis.append(class_name.get_attribute('innerHTML'))
#             val = (name, user_names, class_name.get_attribute('innerHTML').split('\n')[1].split(' ')[-1], passwords)
#             print(val)
#     else:
#         page_count = int(now_total) // 6
#         last_count = int(now_total) - page_count * 6
#         for j in range(page_count):
#             for i in range(1, 7):
#                 class_name = wd.find_element(By.CSS_SELECTOR,
#                                              'body > div:nth-child(1) > div.ouchnPc_index > div.ouchnPc_index_main > div.ouchnPc_index_course.w > ul > li:nth-child(%s) > div > div > p' % i)
#
#                 # sql = "INSERT INTO class_model (stu_num, username, class_name,password) VALUES (%s, %s, %s,%s)"
#                 # insert into asd.`test_table` (`username`, `username11`, `username22`) values ('顾弘文', '萧雨泽', '侯立诚');
#                 lis.append(class_name.get_attribute('innerHTML'))
#                 val = (name, user_names, class_name.get_attribute('innerHTML').split('\n')[1].split(' ')[-1],passwords)
#                 print(val)
#             aaa = wd.find_element(By.CSS_SELECTOR,
#                                   'body > div:nth-child(1) > div.ouchnPc_index > div.ouchnPc_index_main > div.ouchnPc_index_course.w > div > button.btn-next')
#             wd.execute_script("arguments[0].click();", aaa)
#             time.sleep(1)
#         for i in range(1, last_count + 1):
#             class_name = wd.find_element(By.CSS_SELECTOR,
#                                          'body > div:nth-child(1) > div.ouchnPc_index > div.ouchnPc_index_main > div.ouchnPc_index_course.w > ul > li:nth-child(%s) > div > div > p' % i)
#             lis.append(class_name.get_attribute('innerHTML'))
#             # sql = "INSERT INTO class_model (stu_num, username, class_name,password) VALUES (%s, %s, %s,%s)"
#             # insert into asd.`test_table` (`username`, `username11`, `username22`) values ('顾弘文', '萧雨泽', '侯立诚');
#             val = (name, user_names, class_name.get_attribute('innerHTML').split('\n')[1].split(' ')[-1], passwords)
#
# for i in lis:
#     print(i.split('\n')[1].split(" "))
#     print(i.strip())
# wd.find_element(By.CSS_SELECTOR, 'body > div > div.box > img')
# sql = "INSERT INTO class_model (stu_num, username, class_name,password) VALUES (%s, %s, %s, %s)"
# val = (123, 456, '出现错误', '账号或密码失效')
# print(val)
# cursor.execute(sql, val)
# print('xxxx')
# conn.commit()
# cursor.close()
# print('xxxxxxxxxxxxxxxxx')
# conn.close()


#
# time.sleep(60)

# lis = [i for i in range(10)]

# for i in lis:
#     if i <6:
#         print(i)
#
# for i in lis:
#     if i<6:
#         pass
#     else:
#         print(i)

# a = ['毛泽东思想和中国特色社会主义理论体系概论', '地域文化（专）', '形势与政策', '', '信息技术应用', '实用法律基础', '思想道德与法治', '乡镇行政管理', '国家开放大学学习指南', '习近平新时代中国特色社会主义思想', '形势与政策', '土地利用规划', '法律文书', '国际经济法', '形势与政策', '知识产权法', '汉语通论', '比较初等教育', '人类与社会', '儿童发展问题的咨询与辅导', '形势与政策', '课程与教学论', '汉语通论', '比较初等教育', '课程与教学论', '儿童发展问题的咨询与辅导', '形势与政策', '人类与社会', '', '心理健康教育', '', '心理健康教育', '国家开放大学学习指南', '习近平新时代中国特色社会主义思想', '现代教育原理', '习近平总书记教育重要论述研究', '人文英语3', '形势与政策', '现代教育原理', '习近平新时代中国特色社会主义思想', '习近平总书记教育重要论述研究', '形势与政策', '人文英语3', '国家开放大学学习指南', '现代教师学导论＃', '人文英语4', '中国近现代史纲要', '教育研究方法＃', '科学与技术', '名胜古迹与文化', '中国近现代史纲要', '现代教师学导论＃', '科学与技术', '教育研究方法＃', '人文英语4', '名胜古迹与文化', '小学儿童教育心理学＃', '马克思主义基本原理', '小学儿童教育心理学＃', '马克思主义基本原理', '课程与教学论', '比较初等教育', '人类与社会', '儿童发展问题的咨询与辅导', '形势与政策', '汉语通论', '', '心理健康教育', '国家开放大学学习指南', '形势与政策', '现代教育原理', '习近平新时代中国特色社会主义思想', '习近平总书记教育重要论述研究', '人文英语3', '中国近现代史纲要', '人文英语4', '科学与技术', '教育研究方法＃', '现代教师学导论＃', '名胜古迹与文化', '小学儿童教育心理学＃', '马克思主义基本原理', '']
# a = ['人类与社会', '形势与政策', '课程与教学论', '比较初等教育', '汉语通论', '儿童发展问题的咨询与辅导', '', '心理健康教育', '现代教育原理', '习近平总书记教育重要论述研究', '形势与政策', '人文英语3', '国家开放大学学习指南', '习近平新时代中国特色社会主义思想', '人文英语4', '现代教师学导论＃', '名胜古迹与文化', '中国近现代史纲要', '教育研究方法＃', '科学与技术', '小学儿童教育心理学＃', '马克思主义基本原理', '']
# for i in a:
#     print(i)

